package ACWing.Greed;
//913. 排队打水

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author :chenjie
 * @date :Created 2023/1/15 21:38
 */
public class LineUPForWater {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[]arr=new int[n];
        for (int i = 0; i < n; i++) {
            arr[i]=sc.nextInt();
        }
        Arrays.sort(arr);
        int sum=0;long max=0;
        for (int i = 0; i < n; i++) {
            max+=sum;
            sum+=arr[i];
        }
        System.out.println(max);
    }
}
